package com.cn.zengzeng.spbzengzeng.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * @Description:
 * @Author: zhangzengzeng
 * @Date: 2021/7/8 15:48
 */
public enum CodeAndMsgEnum implements ErrorCode{
    /*
    *错误代码类型
    * */
    SUCCESS("200", "成功"),
    FAILD("403","失败"),
    ERROR("500","异常"),
    //执行方法时遇到错误
    METHODFAIL("1005", "执行方法时遇到错误"),
    //这是一个未知的例外
    UNKNO("3000", "未知异常请联系管理员!"),
    //令牌无效
    TOKEN("1001","令牌无效!"),
    TOKEN_ILLEGAL("1002","TOKEN不合法!"),
    //权限
    PERMISSION("5001","系统权限限制"),
    //非法参数异常
    PARAMETER("5002","非法参数异常"),
    //异常访问
    ABNORMAL("5003","异常访问"),
    //没有结果的查询
    QUERY("5004","没有结果的查询"),
    //重复注册
    REGISTER("5005","请勿重复注册!"),
    //激活失败
    ACTIVE("5006","账号激活失败!"),
    //激活超时
    ACTIVE_TIMEOUT("5007","激活超时!"),
    //重复激活
    REPEAT_ACTIVE("5008","请勿重复激活!"),
    TRY_ACTIVE_EMAIL("5009","重试激活账号邮箱与注册邮箱不一致!"),
    REGISTE_ACCOUNT("5010","请先注册账号!"),
    PAWWORD_ERROR("5011","密码错误!"),
    REGISTER_EMAIL("5012","该邮箱已被绑定其他账号!"),
    EMAIL_UNBINDING("5013","该邮箱未绑定账号!"),
    EMAIL_OR_ACCOUNT_NOT("5014","邮箱或账号不匹配!"),
    VERIFICATIONCODE_NOT("5015","验证码不正确!");
    private final String code;
    private final String msg;

    CodeAndMsgEnum (String code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String getCode () {
        return code;
    }

    @Override
    public String getDescription () {
        return msg;
    }
    /**
     * 根据编码查询枚举。
     *
     * @param code 编码。
     * @return 枚举。
     */
    public static CodeAndMsgEnum getByCode(String code) {
        for (CodeAndMsgEnum value : CodeAndMsgEnum.values()) {
            if (StringUtils.equals(code, value.getCode())) {
                return value;
            }
        }
        return UNKNO;
    }

    /**
     * 枚举是否包含此code
     * @param code 枚举code
     * @return 结果
     */
    public static Boolean contains(String code){
        for (CodeAndMsgEnum value : CodeAndMsgEnum.values()) {
            if (StringUtils.equals(code, value.getCode())) {
                return true;
            }
        }
        return  false;
    }

    @Override
    public String toString () {
        return "CodeAndMsgEnum{" + "code='" + code + '\'' + ", msg='" + msg + '\'' + '}';
    }

}
